package com.jike.shop.cloud.mq.listener;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson;
import com.jike.shop.cloud.entity.OrderInfo;
import com.jike.shop.cloud.entity.OrderProduct;
import com.jike.shop.cloud.mapper.OrderInfoMapper;
import com.jike.shop.cloud.mapper.OrderProductMapper;
import com.jike.shop.cloud.service.OrderInfoService;
import com.jike.shop.common.utils.SnowFlakeGenerateIdWorker;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.junit.jupiter.api.Order;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "MyConsumerGroup", topic = "OrderStatusUpdate",messageModel = MessageModel.CLUSTERING,
    selectorType = SelectorType.TAG, selectorExpression = "pay")
public class RocketMQConsumer implements RocketMQListener<String> {

    @Autowired
    private OrderInfoService orderInfoService;

    /**
     * 订单消费支付成功消息，主要逻辑就是拆单
     * @param msg
     */
    @Override
    public void onMessage(String msg) {
        OrderInfo receiveOrder = new Gson().fromJson(msg, OrderInfo.class);
        orderInfoService.splitOrder(receiveOrder);
        log.info("消费消息【{}】", msg);
    }


}
